<?php
namespace app\dboard\controller;
use think\captcha;
use think\facade\Cookie;
use think\facade\Session;
use think\facade\Url;
use think\Db;
class Shop extends Base
{
    public function initialize() {
        parent::initialize();
        $returnUrl=Url::build('dboard/mlogin/sign');
        if(!isset($this->AdminAccount['AdminID']) || intval($this->AdminAccount['AdminID'])<=0 || !isset($this->AdminAccount['sid'])){
            if($this->request->isAjax()){
                return $this->print_result(['Code'=>9999,'Msg'=>'请登录']);
            }
            return $this->redirect($returnUrl);
        }
    }
    public function shop_info(){
        return view('shop/add_shop_info');
    }
    public function edit_pwd(){
        return view('shop/edit_pwd');
    }
   public function editShopinfo(){
        if (!$this->request->isAjax()) {
            $this->res_data['Msg'] = '请求方式错误';
            return $this->print_result($result);
        }
        $param    = $this->request->param(false);
        $shop= Controller('Shop', 'logic');
        $result            = $shop->edit($param);
        return $this->print_result($result);
   }
   public function editShopPwd(){
        if (!$this->request->isAjax()) {
            $this->res_data['Msg'] = '请求方式错误';
            return $this->print_result($result);
        }
        $param    = $this->request->param(false);
        $shop= Controller('Shop', 'logic');
        $result            = $shop->editpwd($param);
        return $this->print_result($result);
   }
    public function infoData(){
        if (!$this->request->isAjax()) {
            $this->res_data['Msg'] = '请求方式错误';
            return $this->print_result($this->res_data);
        }
        $input = $this->request->param(false);
        $id = isset($input['sid'])?$input['sid']:0;
        if(!$id){
            $this->res_data['Msg'] = '参数有误';
            return $this->print_result($this->res_data);
        }
        $where = [];
        $where[] = ['id','=',$id];
        $info = Db::name('store')
                ->where($where)
                ->find();
        $info['create_date'] = date('Y-m-d H:i',$info['createtime']);
        $info['wxcode'] = config('http_domain').$info['wxcode'];
        /*
        $store_photos = Db::name('store_photo')->where([['sid','=',$id]])->select();
        $pts = [];
        foreach($store_photos as $v){
          //$pts[] = get_newpic_url($v['path']);
          $pts[] = $v['path'];
        }
        $info['store_photos'] = $pts;
        */
        $info['pics1'] = '';
        if($info['pic1']) 
          $info['pics1'] = get_newpic_url($info['pic1']);
        $info['pics2'] = '';
        if($info['pic2']) 
          $info['pics2'] = get_newpic_url($info['pic2']);
        $info['pics3'] = '';
        if($info['pic3']) 
          $info['pics3'] = get_newpic_url($info['pic3']);

        $info['vpics1'] = '';
        if($info['vpic1'])
          $info['vpics1'] = get_newpic_url($info['vpic1']);
        $info['vpics2'] = '';
        if($info['vpic2'])
          $info['vpics2'] = get_newpic_url($info['vpic2']);
        $info['vpics3'] = '';
        if($info['vpic3'])
          $info['vpics3'] = get_newpic_url($info['vpic3']);

        $this->res_data['Msg']='OK';
        $this->res_data['Code']=0;
        $this->res_data['Data']=['store'=>$info];
        return $this->print_result($this->res_data);
   }
}
